/**
 * Copyright (C) 2021-2022 maminjie <canpool@163.com>
 * SPDX-License-Identifier: LGPL-2.1
 * Powered by Qt-Advanced-Docking-System
**/

#pragma once

#include "qads_global.h"

#include <QWidget>
#include <QHash>
#include <QPointer>
#include <QRect>

QADS_BEGIN_NAMESPACE

class DockOverlayCross;
class DockOverlayPrivate;

/**
 * DockOverlay paints a translucent rectangle over another widget. The geometry
 * of the rectangle is based on the mouse location.
 */
class QADS_EXPORT DockOverlay : public QWidget
{
    Q_OBJECT
public:
    enum Mode { ModePannelOverlay, ModeContainerOverlay };

    DockOverlay(QWidget *parent, Mode mode = ModePannelOverlay);
    ~DockOverlay() override;

    void setAllowedAreas(DockWidgetAreas areas);
    DockWidgetAreas allowedAreas() const;

    DockWidgetArea dropAreaUnderCursor() const;
    DockWidgetArea visibleDropAreaUnderCursor() const;

    DockWidgetArea showOverlay(QWidget *target);
    void hideOverlay();

    void enableDropPreview(bool enable);
    bool dropPreviewEnabled() const;

    QRect dropOverlayRect() const;

protected:
    bool event(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
    void showEvent(QShowEvent *event) override;
    void hideEvent(QHideEvent *event) override;

private:
    DockOverlayPrivate *d;
    friend class DockOverlayPrivate;
    friend class DockOverlayCross;
};

class DockOverlayCrossPrivate;
/**
 * DockOverlayCross shows a cross with 5 different drop area possibilities.
 * I could have handled everything inside DockOverlay, but because of some
 * styling issues it's better to have a separate class for the cross.
 * You can style the cross icon using the property system.
 * \code
 * QAds--DockOverlayCross
 * {
 *     qproperty-iconBorderColor: palette(highlight);
 *     qproperty-iconWindowColor: palette(base);
 *     qproperty-iconOverlayColor: palette(highlight);
 *     qproperty-iconArrowColor: rgb(227, 227, 227);
 *     qproperty-iconShadowColor: rgb(0, 0, 0);
 * }
 * \endcode
 * Or you can use the iconColors property to pass in AARRGGBB values as
 * hex string like shown in the example below.
 * \code
 * QAds--DockOverlayCross
 * {
 *     qproperty-iconColors: "Border=#ff3d3d3d Window=#ff929292 Overlay=#1f3d3d3d Arrow=#ffb4b4b4 Shadow=#40474747";
 * }
 * \endcode
 */
class DockOverlayCross : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(QString iconColors READ iconColors WRITE setIconColors)
    Q_PROPERTY(QColor iconBorderColor READ iconColor WRITE setIconBorderColor)
    Q_PROPERTY(QColor iconWindowColor READ iconColor WRITE setIconWindowColor)
    Q_PROPERTY(QColor iconOverlayColor READ iconColor WRITE setIconOverlayColor)
    Q_PROPERTY(QColor iconArrowColor READ iconColor WRITE setIconArrowColor)
    Q_PROPERTY(QColor iconShadowColor READ iconColor WRITE setIconShadowColor)

public:
    enum ColorRole {
        Border,     ///< the color of the frame of the small window icon
        Window,     ///< the background color of the small window in the icon
        Overlay,    ///< the color that shows the overlay (the dock side) in the icon
        Arrow,      ///< the arrow that points into the direction
        Shadow,     ///< the color of the shadow rectangle that is painted below the icons
    };
    static const int COLOR_ROLE_CNT = 5;

public:
    DockOverlayCross(DockOverlay *overlay);
    ~DockOverlayCross() override;

    QColor iconColor(ColorRole role) const;
    void setIconColor(ColorRole role, const QColor &color);
    void setIconColors(const QString &colors);

    DockWidgetArea cursorLocation() const;
    void updatePosition();

    void setupOverlayCross(DockOverlay::Mode mode);

    void updateOverlayIcons();

    void reset();

protected:
    void setAreaWidgets(const QHash<DockWidgetArea, QWidget *> &widgets);

    /**
     * This function returns an empty string and is only here to silence moc
     */
    QString iconColors() const;

    /**
     * This is a dummy function for the property system
     */
    QColor iconColor() const { return QColor(); }
    void setIconBorderColor(const QColor &color) { setIconColor(Border, color); }
    void setIconWindowColor(const QColor &color) { setIconColor(Window, color); }
    void setIconOverlayColor(const QColor &color) { setIconColor(Overlay, color); }
    void setIconArrowColor(const QColor &color) { setIconColor(Arrow, color); }
    void setIconShadowColor(const QColor &color) { setIconColor(Shadow, color); }

protected:
    void showEvent(QShowEvent *event) override;

private:
    DockOverlayCrossPrivate *d;
    friend class DockOverlayCrossPrivate;
    friend class DockOverlay;
}; // DockOverlayCross

QADS_END_NAMESPACE
